---
--类名: Transfer.lua
--创建日期: 2015-1-13
--创建人: 陈小虎
--功能描述: 传送ui
--修改内容:
--修改日期:   
--修改人:     
--修改备注: 
--

local Transfer = class("Transfer",function()
    return display.newLayer("Transfer")
end)

function Transfer:ctor(overCall)
	self.mOverCall = overCall

	self.mUINode = cc.uiloader:load(Res.TransferUi)
    self:addChild(self.mUINode)
    self.mUINode:setContentSize(display.width,display.height)
    ccui.Helper:doLayout(self.mUINode)

    local transferwaittimeStr = tonumber(S("transferwaittime")) or 3000
    local transferWaitTime = transferwaittimeStr / 1000
    self:setWaitTime(transferWaitTime)

    self:addStopListener()
end

function Transfer:addStopListener()
    local btnStop = self.mUINode:findChild("goto/StopButton")
    btnStop:addClickEventListener(function(sender)
        self:stopCall()
    end)
end

function Transfer:setStopCallback(stopCall)
    self.mStopCallback = stopCall
end

function Transfer:stopCall()
    if self.mStopCallback then
        self.mStopCallback()
    end
end

function Transfer:setWaitTime(time)
    self.mWaitTime = time
end

function Transfer:playAction()
    local uiAction = cc.CSLoader:createTimeline(Res.TransferUi)
    self:runAction(uiAction)
    uiAction:gotoFrameAndPlay(0,uiAction:getDuration(),false)
end

function Transfer:transferProgress()
    self:playAction()

	local gotoNode = self.mUINode:getChildByName("goto")
	local loadingSprite = gotoNode:getChildByName("Loading")
    loadingSprite:setVisible(false)

    gotoNode:removeChildByTag(150678)

    -- local to = cc.ProgressTo:create(self.mWaitTime / 0.75, 100)
    local to = cc.ProgressTo:create(self.mWaitTime, 100)

    local left = cc.ProgressTimer:create(loadingSprite)
    left:setType(cc.PROGRESS_TIMER_TYPE_RADIAL)
    left:setMidpoint(cc.p(0.5, 0.5))
    left:setAnchorPoint(loadingSprite:getAnchorPoint())
    left:setPosition(cc.p(loadingSprite:getPosition()))
    left:setScale(loadingSprite:getScale())
    left:setTag(150678)
    
    gotoNode:addChild(left)

    local function call()
        gotoNode:removeChild(left)
        if self.mOverCall then
        	self.mOverCall()
        end
    end
    local action = cc.Sequence:create(to,cc.CallFunc:create(call))
    left:runAction(action)
end

return Transfer